// function padLeft(str) {
//   return String(str).length > 1 ? String(str) : "0" + str;
// }

// console.log(padLeft(0));
let arr = [1, 3, 2];
arr.sort((a, b) => a - b);
console.log(arr);
console.log({}.toString());
let o = [
  { id: "01", pid: 0, name: "节点1" },
  { id: "0111", pid: 1, name: "节点1-1-1" },

  { id: "011", pid: 3, name: "节点1-1" },
  { id: "02", pid: 0, name: "节点2" },
  { id: "022", pid: 2, name: "节点2-2" },
  { id: "023", pid: 2, name: "节点2-3" },
  { id: "0222", pid: 2, name: "节点2-2-2" },
  { id: "03", pid: 0, name: "节点3" },
];

function deepClone(o) {
  if (Array.isArray(o)) {
    return o.map((item) => deepClone(item));
  }
  if (Object.prototype.toString.call(o) == "[object Object]") {
    let obj = {};
    for (let key in o) {
      obj[key] = deepClone(o[key]);
    }
    return obj;
  }
  //如果是基本数据类型
  return o;
}

console.log(deepClone(o) == o);

function sortByFiled(target, filed, order) {
  let arr = deepClone(target);
  if (order) {
    arr.sort((a, b) => b[filed] - a[filed]);
  } else {
    arr.sort((a, b) => a[filed] - b[filed]);
  }
  return arr;
}

// console.log(sortByFiled(o, "pid"));
// console.log(sortByFiled(o, "pid", true));
// console.log(sortByFiled(o, "pid") == o);

function isArray(arg) {
  if (!Array.isArray) {
    return Object.prototype.toString.call(arg) === "[object Array]";
  }
  return Array.isArray(arg);
}

console.log(isArray(1));